package pe.com.slcsccy.aegis.model.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import pe.com.slcsccy.aegis.model.beans.Empresa;
import pe.com.slcsccy.aegis.model.beans.EmpresaExample;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository("empresaDAO")
public class EmpresaDAOImpl extends SqlMapClientDaoSupport implements EmpresaDAO {

    /**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public EmpresaDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int countByExample(EmpresaExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"empresa.ibatorgenerated_countByExample", example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int deleteByExample(EmpresaExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"empresa.ibatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int deleteByPrimaryKey(Long idEmpresa) {
		Empresa key = new Empresa();
		key.setIdEmpresa(idEmpresa);
		int rows = getSqlMapClientTemplate().delete(
				"empresa.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public void insert(Empresa record) {
		getSqlMapClientTemplate().insert("empresa.ibatorgenerated_insert",
				record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public void insertSelective(Empresa record) {
		getSqlMapClientTemplate().insert(
				"empresa.ibatorgenerated_insertSelective", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	@SuppressWarnings("unchecked")
	public List<Empresa> selectByExampleWithBLOBs(EmpresaExample example) {
		List<Empresa> list = getSqlMapClientTemplate().queryForList(
				"empresa.ibatorgenerated_selectByExampleWithBLOBs", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	@SuppressWarnings("unchecked")
	public List<Empresa> selectByExampleWithoutBLOBs(EmpresaExample example) {
		List<Empresa> list = getSqlMapClientTemplate().queryForList(
				"empresa.ibatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public Empresa selectByPrimaryKey(Long idEmpresa) {
		Empresa key = new Empresa();
		key.setIdEmpresa(idEmpresa);
		Empresa record = (Empresa) getSqlMapClientTemplate().queryForObject(
				"empresa.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int updateByExampleSelective(Empresa record, EmpresaExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"empresa.ibatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int updateByExampleWithBLOBs(Empresa record, EmpresaExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"empresa.ibatorgenerated_updateByExampleWithBLOBs", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int updateByExampleWithoutBLOBs(Empresa record,
			EmpresaExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"empresa.ibatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int updateByPrimaryKeySelective(Empresa record) {
		int rows = getSqlMapClientTemplate().update(
				"empresa.ibatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int updateByPrimaryKeyWithBLOBs(Empresa record) {
		int rows = getSqlMapClientTemplate().update(
				"empresa.ibatorgenerated_updateByPrimaryKeyWithBLOBs", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	public int updateByPrimaryKeyWithoutBLOBs(Empresa record) {
		int rows = getSqlMapClientTemplate().update(
				"empresa.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table empresa
	 * @ibatorgenerated  Sat May 19 03:00:51 COT 2012
	 */
	private static class UpdateByExampleParms extends EmpresaExample {
		private Object record;

		public UpdateByExampleParms(Object record, EmpresaExample example) {
			super(example);
			this.record = record;
		}

		public Object getRecord() {
			return record;
		}
	}

	@Autowired
    public void createSqlMapClient(@Qualifier("sqlMapClient")  SqlMapClient sqlMapClient){
      setSqlMapClient(sqlMapClient);
    }

	@Override
	public Long nextSecuencia(String nombreSecuencia) {
		// TODO Auto-generated method stub
		Map<String,Object> p = new HashMap<String,Object>();
		p.put("nombreSecuencia", nombreSecuencia);
		return  (Long)getSqlMapClientTemplate().queryForObject("empresa.nextSecuencia",p);
	}   
}